<?
if(!$CFG) require_once('config.php');


if(key_exists('debug',$_GET) && $_GET['debug']) $debug = true;
else $debug = false;

header('Content-Type: application/x-javascript');

if($debug) $file = $CFG->GownFull_javascript_debug_file;
else $file = $CFG->GownFull_javascript_file;

if($debug) {
	header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
	header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
	header('Cache-Control: no-cache, must-revalidate');
	header('Pragma: no-cache');
}
else {
	if(key_exists('HTTP_IF_MODIFIED_SINCE',$_SERVER)) {
		$ims = ereg_replace(';.*$', '',$_SERVER['HTTP_IF_MODIFIED_SINCE']);
		$ims = strtotime($ims);
	}
	else $ims = 0;
	$mtime = filemtime($file);
	if($ims >= $mtime) {
		header('HTTP/1.1 304 Not Modified');
		exit(0);
	}
	header('Cache-Control: max-age='.$CFG->http_cache_max_age);
	header('Last-Modified: '.gmdate('D, d M Y H:i:s',$mtime).' GMT');
}

readfile($file);

// check language

if(key_exists('lang',$_GET)) {
	$path = $CFG->GownFull_LANGPath.$_GET['lang'].'.js';
	if(file_exists($path)) {
		readfile($path);
	}
	else { // this language does not exists
		printf("\n//Language \"%s\" does not exist.\n",$_GET['lang']);
	}
}

// change the config
printf("GownFullConfig.gownfull_base_url = '%s';\r\n",$CFG->GownFull_URL);
printf("GownFullConfig.css_file = '%s';\r\n",$CFG->GownFull_URL . 'gownfull.css');
printf("GownFullConfig.getim_url = '%s';\r\n",$CFG->GownFull_URL . 'getim.php');
printf("GownFullConfig.help_url = '%s';\r\n",$CFG->GownFull_URL . 'help/');

if(key_exists('nocreate',$_GET) && $_GET['nocreate']) {
}
else {
	printf("new GownFull(new GenericGownFullBuilder);\r\n");

	// install modifiers
	//printf("%s.modifiers.push(new RingBufferOutputModifier(%s,1000));\r\n",$CFG->GownFull_InstanceName,$CFG->GownFull_InstanceName);
	//printf("%s.modifiers.push(new TimerOutputModifier(%s));\r\n",$CFG->GownFull_InstanceName,$CFG->GownFull_InstanceName);
	if($debug) printf("GownFull.instance.modifiers.push(new UnicodeImageOutputModifier(GownFull.instance));\r\n");
	
	if(!$_GET['noregdownload']) {
		foreach($CFG->Available_IM as $im) {
			if(key_exists('url',$im)) printf("GownFull.instance.RegisterDownload('%s',\"%s\",\"%s\");\r\n",$im['objname'],$im['displayname'],$im['url']);
			else printf("GownFull.instance.RegisterDownload('%s',\"%s\");\r\n",$im['objname'],$im['displayname']);
		}
	}
}
?>
